home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6584 / 6584.xpi / chrome / flashvideodownloader / content / options.js < prev    next >
Text File  |  2009-11-18  |  3KB  |  95 lines

  1.  
  2. var FlashVDOptions = {
  3.  
  4.     options : null,
  5.     _hotkey : null, // need to store edited values to handle "ok"
  6.     _hot_mod: null,
  7.     
  8.     init : function()
  9.     {
  10.         this.options = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("FlashVD.options.");
  11.         
  12.         var hotkey;
  13.         var hot_mod;
  14.         var opt_sel_k=window.document.getElementById('opt_hotk');
  15.         var opt_sel_m=window.document.getElementById('opt_hotm');
  16.         try{hotkey=this.options.getCharPref('hotkey');}catch(e){}
  17.         try{hot_mod=this.options.getCharPref('hot_mod');}catch(e){}
  18.  
  19.         if(hotkey)
  20.         {
  21.             opt_sel_k.selectedItem=opt_sel_k.getElementsByAttribute("label",hotkey)[0];
  22.             this._hotkey = hotkey;
  23.         }
  24.         else
  25.         {
  26.             opt_sel_k.selectedItem=opt_sel_k.getElementsByAttribute("label","L")[0];
  27.         }
  28.         if(hot_mod)
  29.         {
  30.             var tikva;
  31.             if(hot_mod=='alt any control')tikva=" alt";
  32.             if(hot_mod=='shift any control')tikva="shift";
  33.             opt_sel_m.selectedItem=opt_sel_m.getElementsByAttribute("label",tikva)[0];
  34.             this._hot_mod = hot_mod;
  35.         }
  36.         else
  37.         {
  38.             opt_sel_m.selectedItem=opt_sel_m.getElementsByAttribute("label"," alt")[0];
  39.         }
  40.         
  41.         window.sizeToContent();
  42.     },
  43.     
  44.     set_hotk : function(){
  45.         this._hotkey = window.document.getElementById('opt_hotk').selectedItem.value;
  46.     },
  47.     
  48.     set_hotm : function(){
  49.         var modifier=window.document.getElementById('opt_hotm').selectedItem.value;
  50.         var tikva;
  51.         if(modifier=='alt'){tikva='alt any control';}
  52.         if(modifier=='shift'){tikva='shift any control';}
  53.         this._hot_mod = tikva;
  54.     },
  55.     
  56.     get_folder : function() {
  57.         var folder = this.onPickFolder();
  58.         if (folder)
  59.             this.set_folder(folder);
  60.     },
  61.  
  62.     set_folder : function(folder) {
  63.         window.document.getElementById('fav_folder_text').value=folder;
  64.     },
  65.     
  66.     onPickFolder : function(){
  67.         var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
  68.         fp.init(window,'Choose folder for videos and games:', Components.interfaces.nsIFilePicker.modeGetFolder);
  69.         var res = fp.show();
  70.         if (res == Components.interfaces.nsIFilePicker.returnOK)
  71.             return fp.file.path;
  72.         return false;
  73.     },
  74.  
  75.     acceptEdit : function () {
  76.         // current logic is too complicated to use preference for hotkeys - refactoring neded
  77.         if (this._hotkey != null) this.options.setCharPref('hotkey', this._hotkey);
  78.         if (this._hot_mod!= null) this.options.setCharPref('hot_mod',this._hot_mod);
  79.  
  80.         // preference realization doesn't store path if we changed it programmatically (onPickFolder)
  81.         var s = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  82.         s.data = window.document.getElementById('fav_folder_text').value;
  83.         this.options.setComplexValue("favorite-folder", Components.interfaces.nsISupportsString, s);
  84.         
  85.     },
  86.  
  87.     restore_defaults : function () {
  88.         
  89.         this.options.deleteBranch("");
  90.         Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("FlashVD.cache.").deleteBranch("");
  91.         
  92.         window.close();
  93.     }
  94.     
  95. } // FlashVDOptions